<?php


namespace app\common\model;


use think\facade\Db;
use think\Model;

class Detailed extends Model
{
    /*** 获取资金明细
     * @param array $where
     * @param $pageIndex
     * @param $pageSize
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function detailedList(array $where,$pageIndex,$pageSize){
        return self::where($where)->order('addtime desc,id desc')->page($pageIndex,$pageSize)->select();
    }

    /*** 获取资金明细总条数
     * @param array $where
     * @return int
     */
    public static function detailedCount(array $where){
        return intval(self::where($where)->count());
    }

    /** 单个资金记录增加
     * @param array $data
     * @return Detailed|Model
     */
    public static function detailedAdd(array $data){
        return self::create($data);
    }

    /***    批量插入资金记录
     * @param array $data
     * @return int
     */
    public static function detailedAddAll(array $data){
        return self::insertAll($data);
    }

    /*** 获取一定条件下的资金操作总和
     * @param $where
     * @return float
     */
    public static function detailedSum($where){
        return self::where($where)->sum('amount_money');
    }

    /*** 获取一定条件下的 资金明细
     * @param $where
     * @return array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function detailedView($where){
        return self::where($where)->find();
    }

    public static function detailedEdit($where,$data){
        return self::update($data,$where);
    }
}